package com.cmlite.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class MySQLiteHelper extends SQLiteOpenHelper{

	  public static final String TABLE_PROFILE = "tb_profile";
	  public static final String COLUMN_ID = "_id";
	  public static final String COLUMN_EMAIL = "_email";
	  public static final String COLUMN_PASSWORD = "_password";
	  public static final String COLUMN_FULL_NAME = "_full_name";
	  public static final String COLUMN_FIRST_NAME = "_first_name";
	  public static final String COLUMN_LAST_NAME = "_last_name";
	  public static final String COLUMN_PHONE = "_phone";
	  public static final String COLUMN_PHONE_OTHER = "_phone_other";
	  public static final String COLUMN_ADDRESS = "_address";
	  public static final String COLUMN_ADDRESS_OTHER = "_address_other";
	  public static final String COLUMN_GENDER = "_gender";
	  public static final String COLUMN_BIRTHDAY = "_birthday";

	  private static final String DATABASE_NAME = "db_appcontact.db";
	  private static final int DATABASE_VERSION = 1;

	  // Database creation sql statement
	  private static final String DATABASE_CREATE = "create table " + TABLE_PROFILE + 
			  "(" + COLUMN_ID + " INTEGER PRIMARY KEY, " + // AUTOINCREMENT, " + 
			  COLUMN_EMAIL + " NVARCHAR(50) NOT NULL, " +
			  COLUMN_FULL_NAME + " NVARCHAR(100), " + 
			  COLUMN_FIRST_NAME + " NVARCHAR(50), " +
			  COLUMN_LAST_NAME + " NVARCHAR(50), " +
			  COLUMN_PHONE + " VARCHAR(50), " +
			  COLUMN_PHONE_OTHER + " VARCHAR(50), " +
			  COLUMN_ADDRESS + " TEXT, " +
			  COLUMN_ADDRESS_OTHER + " TEXT, " +
			  COLUMN_GENDER + " INTEGER NOT NULL, " + 	// 0: None | 1: Male | 2: Female
			  COLUMN_BIRTHDAY + " VARCHAR(20)" +
			  ");";

	  public MySQLiteHelper(Context context) {
	    super(context, DATABASE_NAME, null, DATABASE_VERSION);
	  }

	  @Override
	  public void onCreate(SQLiteDatabase database) {
	    database.execSQL(DATABASE_CREATE);
	  }

	  @Override
	  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
	    Log.w(MySQLiteHelper.class.getName(),
	        "Upgrading database from version " + oldVersion + " to "
	            + newVersion + ", which will destroy all old data");
	    db.execSQL("DROP TABLE IF EXISTS " + TABLE_PROFILE);
	    onCreate(db);
	  }
}
